home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!hester
- From: hester@netcom.com (Jim Hester)
- Subject: [Borland's?] new: xalloc exception shoots itself in the foot?
- Message-ID: <hesterDn1F1H.LKr@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- Distribution: usa
- Date: Mon, 19 Feb 1996 19:20:05 GMT
- Sender: hester@netcom9.netcom.com
-
- This may be Borland specific:
-
- I recently ran a program that allocated a lot of small nodes (I was
- performing a breadth-first search of my hard drive) and ran out of
- space. My system locked up. My best guess (experimentation appears to
- support this) is that this is what happened:
-
- The "new" operator threw an xalloc exception. xalloc contains a string
- class object, which attempts to allocate an array of chars. Since there
- was no memory available, another xalloc exception was thrown and the
- "exception loop" continued.
-
- Am I missing something, or is this as stupid as it appears to be?
- What possible justification could there be for having the default
- action of allocation failure be to try allocating again?
-
- In the case of memory exceptions, I tend to try to trap them as early as
- possible and throw an equivalent exception with a more descriptive
- string giving the location of the fault. Each layer up from there I
- again try to trap and add information ONLY if it wasn't added at a
- deeper layer (that way I get the closest approximation to where the
- error actually occurred). I can save run-time problems with this
- practice to some extent by keeping static exception objects at each
- place where I might want them, pre-initialized with appropriate strings.
- However, this doesn't help at all with the FIRST exception: the one that
- is actually thrown by the "new" operator.
-
- I understand that I can override the "exceptional" behavior and
- re-institute a nice safe NULL return policy. My purpose here is one of
- curiosity (and in case I've missed something). What were the designers
- thinking????
-
- Thanks in advance,
- _
- / ) *
- (_/ . __ /
- / /\_/_///_ |
- (_/ |
- |\
- * | \ *
- | \
- | \ \
- | \/ \/
- /
- *
- Redundency avoided: look my address up in the message headers.
- Oops, the line above wasts even more space than my address would have!
- Oh, My!!! I wasted even MORE space!!
- AAAcccckkkkk! I did it AGAIN!!!!!
- (Sorry, I was got back from a convention where Monty Python references
- were prevalent.)
-